home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 21
/
Cream of the Crop 21 (Terry Blount) (October 1996).iso
/
os2
/
e33el2.zip
/
emacs
/
19.33
/
lisp
/
refbib.el
< prev
next >
Wrap
Lisp/Scheme
|
1996-01-20
|
25KB
|
733 lines
;;; refbib.el --- convert refer-style references to ones usable by Latex bib
;; Copyright (C) 1989 Free Software Foundation, Inc.
;; Author: Henry Kautz <kautz@research.att.com>
;; Keywords: bib, tex
;; This file is part of GNU Emacs.
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;; Use: from a buffer containing the refer-style bibliography,
;; M-x r2b-convert-buffer
;; Program will prompt for an output buffer name, and will log
;; warnings during the conversion process in the buffer *Log*.
;;; Change Log:
;; HISTORY
;; 9/88, created H.Kautz
;; modified 1/19/89, allow books with editor but no author;
;; added %O ordering field;
;; appended illegal multiple fields, instead of
;; discarding;
;; added rule, a tech report whose %R number
;; contains "ISBN" is really a book
;; added rule, anything with an editor is a book
;; or a proceedings
;; added 'manual type, for items with institution
;; but no author or editor
;; fixed bug so trailing blanks are trimmed
;; added 'proceedings type
;; used "organization" field for proceedings
;; modified 2/16/89, updated help messages
;; modified 2/23/89, include capitalize stop words in r2b stop words,
;; fixed problems with contractions (e.g. it's),
;; caught multiple stop words in a row
;; modified 3/1/89, fixed capitalize-title for first words all caps
;; modified 3/15/89, allow use of " to delimit fields
;; modified 4/18/89, properly "quote" special characters on output
;;; Code:
;**********************************************************
; User Parameters
(defvar r2b-trace-on nil "*trace conversion")
(defvar r2b-journal-abbrevs
'(
)
" Abbreviation list for journal names.
If the car of an element matches a journal name exactly, it is replaced by
the cadr when output. Braces must be included if replacement is a
{string}, but not if replacement is a bibtex abbreviation. The cadr
may be eliminated if is exactly the same as the car.
Because titles are capitalized before matching, the abbreviation
for the journal name should be listed as beginning with a capital
letter, even if it really doesn't.
For example, a value of '((\"Aij\" \"{Artificial Intelligence}\")
\(\"Ijcai81\" \"ijcai7\")) would expand Aij to the text string
\"Artificial Intelligence\", but would replace Ijcai81 with the
BibTeX macro \"ijcai7\".")
(defvar r2b-booktitle-abbrevs
'(
)
" Abbreviation list for book and proceedings names. If the car of
an element matches a title or booktitle exactly, it is replaced by
the cadr when output. Braces must be included if replacement is
a {string}, but not if replacement is a bibtex abbreviation. The cadr
may be eliminated if is exactly the same as the car.
Because titles are capitalized before matching, the abbreviated title
should be listed as beginning with a capital letter, even if it doesn't.
For example, a value of '((\"Aij\" \"{Artificial Intelligence}\")
\(\"Ijcai81\" \"ijcai7\")) would expand Aij to the text string
\"Artificial Intelligence\", but would replace Ijcai81 with the
BibTeX macro \"ijcai7\".")
(defvar r2b-proceedings-list
'()
" Assoc list of books or journals which are really conference proceedings,
but whose name and whose abbrev expansion (as defined in `r2b-journal-abbrevs'
and `r2b-booktitle-abbrevs') does not contain the words \"conference\" or
\"proceedings\". (Those cases are handled automatically.)
The entry must match the given data exactly.
Because titles are capitalized before matching, the items in this list
should begin with a capital letter.
For example, suppose the title \"Ijcai81\" is used for the proceedings of
a conference, and it's expansion is the BibTeX macro \"ijcai7\". Then
`r2b-proceedings-list' should be '((\"Ijcai81\") ...). If instead its
expansion were \"Proceedings of the Seventh International Conference
on Artificial Intelligence\", then you would NOT need to include Ijcai81
in `r2b-proceedings-list' (although it wouldn't cause an error).")
(defvar r2b-additional-stop-words
"Some\\|What"
"Words other than the `capitalize-title-stop-words'
which are not to be used to build the citation key")
(defvar r2b-delimit-with-quote
t
"*If true, then use \" to delimit fields, otherwise use braces")
;**********************************************************
; Utility Functions
(defvar capitalize-title-stop-words
(concat
"the\\|and\\|of\\|is\\|a\\|an\\|of\\|for\\|in\\|to\\|in\\|on\\|at\\|"
"by\\|with\\|that\\|its")
"Words not to be capitalized in a title (unless they are the first
word in the title)")
(defvar capitalize-title-stop-regexp
(concat "\\(" capitalize-title-stop-words "\\)\\(\\b\\|'\\)"))
(defun capitalize-title-region (begin end)
"Like `capitalize-region', but don't capitalize stop words, except the first."
(interactive "r")
(let ((case-fold-search nil) (orig-syntax-table (syntax-table)))
(unwind-protect
(save-restriction
(set-syntax-table text-mode-syntax-table)
(narrow-to-region begin end)
(goto-char (point-min))
(if (looking-at "[A-Z][a-z]*[A-Z]")
(forward-word 1)
(capitalize-word 1))
(while (re-search-forward "\\<" nil t)
(if (looking-at "[A-Z][a-z]*[A-Z]")
(forward-word 1)
(if (let ((case-fold-search t))
(looking-at capitalize-title-stop-regexp))
(downcase-word 1)
(capitalize-word 1)))
))
(set-syntax-table orig-syntax-table))))
(defun capitalize-title (s)
"Like capitalize, but don't capitalize stop words, except the first."
(save-excursion
(set-buffer (get-buffer-create "$$$Scratch$$$"))
(erase-buffer)
(insert s)
(capitalize-title-region (point-min) (point-max))
(buffer-string)))
;*********************************************************
(defun r2b-reset ()
"Unbind defvars, for debugging."
(interactive)
(makunbound 'r2b-journal-abbrevs)
(makunbound 'r2b-booktitle-abbrevs)
(makunbound 'r2b-proceedings-list)
(makunbound 'capitalize-title-stop-words)
(makunbound 'capitalize-title-stop-regexp)
(makunbound 'r2b-additional-stop-words)
(makunbound 'r2b-stop-regexp))
(defvar r2b-stop-regexp
(concat "\\`\\(\\("
r2b-additional-stop-words "\\|" capitalize-title-stop-words
"\\)\\('\\w*\\)?\\W+\\)*\\([A-Z0-9]+\\)"))
(defun r2b-trace (&rest args)
(if r2b-trace-on
(progn
(apply (function message) args)
(sit-for 0))))
(defun r2b-match (exp)
"Returns string matched in current buffer."
(buffer-substring (match-beginning exp) (match-end exp)))
(defvar r2b-out-buf-name "*Out*" "*output from refer-to-bibtex" )
(defvar r2b-log-name "*Log*" "*logs errors from refer-to-bibtex" )
(defvar r2b-in-buf nil)
(defvar r2b-out-buf nil)
(defvar r2b-log nil)
(defvar r2b-error-found nil)
(setq r2b-variables '(
r2b-error-found
r2bv-author
r2bv-primary-author
r2bv-date
r2bv-year
r2bv-decade
r2bv-month
r2bv-title
r2bv-title-first-word
r2bv-editor
r2bv-annote
r2bv-t